package com.ht.medicaltreatment.utils

import android.content.Context
import com.blankj.utilcode.util.TimeUtils
import com.ht.medicaltreatment.R
import com.loper7.date_time_picker.DateTimeConfig
import com.loper7.date_time_picker.dialog.CardDatePickerDialog
import java.lang.ref.WeakReference

object DateUtils {
    fun selectTime(context: Context?, title:String = "选择时间",formatTime:String = "yyyy-MM-dd HH:mm:ss",onSelect:(String)->Unit){
        val weakReference = WeakReference<Context>(context)
        var wContext = weakReference.get()
        if(wContext == null)return
        CardDatePickerDialog.builder(wContext)
            .setTitle(title)
            .showBackNow(false)
            .showFocusDateInfo(false)
            .setThemeColor(wContext.getColor(R.color.blue))
            .setBackGroundModel(CardDatePickerDialog.CUBE)
            .setDisplayType(arrayListOf(
                DateTimeConfig.YEAR,
                DateTimeConfig.MONTH,
                DateTimeConfig.DAY,
                DateTimeConfig.HOUR, DateTimeConfig.MIN, DateTimeConfig.SECOND))
            .setOnChoose {millisecond->
                onSelect(TimeUtils.millis2String(millisecond,formatTime))
                wContext = null
                weakReference.clear()
            }.build().show()
    }
}